package com.leyou.order.listener;

import com.leyou.common.constants.RocketMQConstants;
import com.leyou.order.service.TbOrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.leyou.common.constants.RocketMQConstants.CONSUMER.ORDER_OVERTIME_CONSUMER;
import static com.leyou.common.constants.RocketMQConstants.TAGS.ORDER_OVERTIME_TAGS;
import static com.leyou.common.constants.RocketMQConstants.TOPIC.ORDER_TOPIC_NAME;

@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = ORDER_OVERTIME_CONSUMER,
        topic = ORDER_TOPIC_NAME,
        selectorExpression = ORDER_OVERTIME_TAGS)
public class OverTimeOrderListener implements RocketMQListener<String> {

    @Autowired
    private TbOrderService tbOrderService;

    @Override
    public void onMessage(String overTime) {
        log.info("【订单服务】接收到关闭超时订单消息，overTime：{}",overTime);
        tbOrderService.closeOverTimeOrder(overTime);
    }
}
